const util = require('../../utils/util.js')
const getApps = getApp().globalData

const Monitor = require('../../utils/monitor.js').Monitor
Page(Monitor.hookApp({
  data: {},
  onLoad: function(option) {
    var that = this
    wx.setNavigationBarColor({
      frontColor: '#000000',
      backgroundColor: '#ffffff'
    })
    wx.getSystemInfo({
      success: function(res) {
        that.setData({
          screenheight: res.windowHeight
        })
      }
    })
    this.setData({
      sname: getApps.app_name
    })
  },

  bindGetUserInfo: function(e) {
    var that = this
    if (e.detail.userInfo) {
      wx.showLoading({
        title: '授权中'
      })

      wx.getUserInfo({
        success: function(res) {
          util
            .login(res.userInfo.nickName, res.userInfo.avatarUrl)
            .then(res => {
              wx.hideLoading()
              wx.navigateBack({
                delta: 1
              })
            })
        }
      })
    } else {
      wx.showModal({
        title: '',
        content: '不授权部分功能无法正常使用',
        showCancel: true,
        success: function(res) {
          if (res.confirm) {
            wx.navigateBack({
              delta: 1
            })
          }
        },
        fail: function(res) {},
        complete: function(res) {}
      })
    }
  }
}))
